package net.muhu.channel.service.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;

import javax.xml.bind.JAXBException;

import net.muhu.channel.service.MusiverseServiceFileStorageImpl;
import net.muhu.channel.service.MusiverseServiceFileStorage;
import net.muhu.domain.Galaxy;
import net.muhu.domain.Location;
import net.muhu.domain.Musiverse;

import org.junit.Before;
import org.junit.Test;

public class ReadFromStorageTestCase {

	private static final String MUSIVERSE_ID = "musiverse";

	private static final String STORAGE_XML = "/MusicHuntersStorage.xml";

	private MusiverseServiceFileStorage cut;

	@Before
	public void setup() throws JAXBException, URISyntaxException {
		cut = new MusiverseServiceFileStorageImpl();
		URI uri = this.getClass().getResource(STORAGE_XML).toURI();
		System.out.println(uri);
		cut.setFile(new File(uri));
	}

	@Test
	public void getMusiverse() throws Exception {
		Musiverse actual = cut.getMusiverse(MUSIVERSE_ID);
		assertEquals(MUSIVERSE_ID, actual.getId());

		Location location = actual.getLocation().get(0);
		assertTrue(location instanceof Galaxy);
		assertEquals("milky_way", location.getId());
	}
}
